@extends('admin.layouts.app')

@section('title', '角色详情')

@section('content')
<div class="d-flex justify-content-between align-items-center mb-3">
    <h3>角色详情</h3>
    <div>
        @can('edit-roles')
        <a href="{{ route('admin.roles.edit', $role) }}" class="btn btn-warning">
            <i class="fas fa-edit me-2"></i>编辑
        </a>
        @endcan
        <a href="{{ route('admin.roles.index') }}" class="btn btn-secondary">
            <i class="fas fa-arrow-left me-2"></i>返回列表
        </a>
    </div>
</div>

<div class="row">
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">基本信息</h5>
            </div>
            <div class="card-body">
                <table class="table table-borderless">
                    <tr>
                        <td width="30%"><strong>ID:</strong></td>
                        <td>{{ $role->id }}</td>
                    </tr>
                    <tr>
                        <td><strong>角色名称:</strong></td>
                        <td>{{ $role->name }}</td>
                    </tr>
                    <tr>
                        <td><strong>守卫:</strong></td>
                        <td>{{ $role->guard_name }}</td>
                    </tr>
                    <tr>
                        <td><strong>创建时间:</strong></td>
                        <td>{{ $role->created_at->format('Y-m-d H:i:s') }}</td>
                    </tr>
                    <tr>
                        <td><strong>更新时间:</strong></td>
                        <td>{{ $role->updated_at->format('Y-m-d H:i:s') }}</td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">权限列表 ({{ $role->permissions->count() }})</h5>
            </div>
            <div class="card-body">
                @if($role->permissions->count() > 0)
                    <div class="row">
                        @foreach($role->permissions as $permission)
                            <div class="col-md-6 mb-2">
                                <span class="badge bg-primary">{{ $permission->name }}</span>
                            </div>
                        @endforeach
                    </div>
                @else
                    <p class="text-muted">该角色暂无权限</p>
                @endif
            </div>
        </div>
    </div>
</div>

<div class="row mt-4">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">拥有此角色的用户 ({{ $role->users->count() }})</h5>
            </div>
            <div class="card-body">
                @if($role->users->count() > 0)
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>姓名</th>
                                    <th>邮箱</th>
                                    <th>创建时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($role->users as $user)
                                <tr>
                                    <td>{{ $user->id }}</td>
                                    <td>{{ $user->name }}</td>
                                    <td>{{ $user->email }}</td>
                                    <td>{{ $user->created_at->format('Y-m-d H:i') }}</td>
                                    <td>
                                        @can('view-users')
                                        <a href="{{ route('admin.users.show', $user) }}" class="btn btn-sm btn-outline-info">
                                            <i class="fas fa-eye"></i> 查看
                                        </a>
                                        @endcan
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                @else
                    <p class="text-muted">暂无用户拥有此角色</p>
                @endif
            </div>
        </div>
    </div>
</div>
@endsection